<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="format-detection" content="telephone=no">
    <meta name="msapplication-tap-highlight" content="no">
    <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">
    <title>Alljs数据管理</title>
    <link rel='stylesheet' href='<%- rootUrl %>/res/adapter.css' />
    <link rel='stylesheet' href='<%- rootUrl %>/node_modules/font-awesome/css/font-awesome.min.css' />
    <style>
        table {font-size:9px}
        td, th {padding:3px}
    </style>
    <script src="<%- rootUrl %>/node_modules/jquery/dist/jquery.min.js"></script>
    <script src="<%- rootUrl %>/res/adapter.js"></script>
</head>
<body class="body-margin">
<alljs-widget><message-top><%- message %></message-top></alljs-widget>
<div style="position:fixed;box-sizing:border-box;padding:16px;background-color:white;border:2px solid black">
    <form action="./manageEverything" method="get">
        表名&nbsp;<select name="col" style="width:8em;height:21px">
        <option value="meta" <%- col==='meta' ? 'selected' : '' %>>meta</option>
        <option value="user" <%- col==='user' ? 'selected' : '' %>>user</option>
        <option value="article" <%- col==='article' ? 'selected' : '' %>>article</option>
        <option value="comment" <%- col==='comment' ? 'selected' : '' %>>comment</option>
        <option value="fond" <%- col==='fond' ? 'selected' : '' %>>fond</option>
        <option value="feedback" <%- col==='feedback' ? 'selected' : '' %>>feedback</option>
        <option value="behavior" <%- col==='behavior' ? 'selected' : '' %>>behavior</option></select>
        &emsp;过滤&nbsp;<input id="filter-text" name="filter" type="text" value="<%= filter %>" style="width:16em" />
        &nbsp;排序&nbsp;<input id="sort" name="sort" type="text" value="<%= sort %>"  style="width:8em" />
        &nbsp;页数&nbsp;<input id="page" name="page" type="number" value="<%= page.pageno %>"  style="width:3em" />&nbsp;
        <input type="submit" />
    </form>
</div>
<form action="./deleteSomething" method="post" style="padding-top:115px">
<div class="childs-vert-middle" style="margin-bottom:6px;font-weight: bold;word-break: keep-all">
<input type="hidden" name="col" value="<%= col %>" />
<input id="filter-hidden" type="hidden" name="filter" value="{&quot;_id&quot;:&quot;N/A&quot;}" />
<input id="type-hidden" type="hidden" name="type" value="" />
<button class="button-likeText" type="submit" onclick="$('#type-hidden').val('delete');$('#filter-hidden').val($('#filter-text').val())" /><i class="fa fa-trash-o"></i></button><span>删除所有</span>
<button class="button-likeText" type="submit" onclick="$('#type-hidden').val('forbid');$('#filter-hidden').val($('#filter-text').val())" /><i class="fa fa-ban"></i></button><span>禁用所有</span> &emsp;&emsp;
<span>(本页为&nbsp;第&nbsp;<%- page.pageno %>&nbsp;页, 第&nbsp;<%- page.from %>&nbsp;-&nbsp;<%- page.to %>&nbsp;条)</span>
</div>
<table border="1" cellspacing="0">
    <tr>
        <th>del</th>
        <th>forbid</th>
        <th>see</th>
        <% for (let field of fields) { %>
        <th><%- field %></th>
        <% } %>
    </tr>
    <% for (let item of items) { %>
    <tr>
        <td><button class="button-likeText" type="submit" onclick="$('#type-hidden').val('delete');$('#filter-hidden').val('{&quot;_id&quot;:&quot;<%- item._id %>&quot;}')" /><i class="fa fa-trash-o"></i></button></td>
        <td style="text-align:center"><button class="button-likeText" type="submit" onclick="$('#type-hidden').val('forbid');$('#filter-hidden').val('{&quot;_id&quot;:&quot;<%- item._id %>&quot;}')" <%- item.status==='1'?'style="color:red"':'' %>/><i class="fa fa-ban"></i></button></td>
        <td style="text-align:center"><i class="fa fa-eye" onclick="var a='<%- item.infoUrl %>'; a ? window.open(a) : showMessage('SEE not support this entity');"></i></td>
        <% for (let field of fields) { %>
        <td><%- item[field] %></td>
        <% }%>
    </tr>
    <% } %>
</table>
</form>
<script src="<%- rootUrl %>/res/manageEverything.js"></script>
<script>
    $(function(){
        window.linkableTable($('table').children('tbody'));

        $('select[name=col]').change(function(){
            $('#filter-text').val('');
            $('#page').val(1);
            let colval = $(this).val();
            let sort = $('input[name=sort]');
            if (colval === 'article' || colval === 'comment' || colval === 'fond' || colval === 'feedback'){
                sort.val('{"produceTime":-1}');
            }else if (colval === 'user'){
                sort.val('{"signupdate":-1}');
            }else if (colval === 'behavior'){
                sort.val('{"t":-1}');
            }
        });
    });
</script>
</body>
</html>
